﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.LogEntries.ClanLeaderChangedLogEntry
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using Helpers;
using System.Collections.Generic;
using TaleWorlds.Localization;
using TaleWorlds.ObjectSystem;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.LogEntries
{
  public class ClanLeaderChangedLogEntry : LogEntry, IEncyclopediaLog
  {
    [SaveableField(160)]
    public readonly Hero OldLeader;
    [SaveableField(161)]
    public readonly Hero NewLeader;

    internal static void AutoGeneratedStaticCollectObjectsClanLeaderChangedLogEntry(
      object o,
      List<object> collectedObjects)
    {
      ((LogEntry) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      base.AutoGeneratedInstanceCollectObjects(collectedObjects);
      collectedObjects.Add((object) this.OldLeader);
      collectedObjects.Add((object) this.NewLeader);
    }

    internal static object AutoGeneratedGetMemberValueOldLeader(object o)
    {
      return (object) ((ClanLeaderChangedLogEntry) o).OldLeader;
    }

    internal static object AutoGeneratedGetMemberValueNewLeader(object o)
    {
      return (object) ((ClanLeaderChangedLogEntry) o).NewLeader;
    }

    public ClanLeaderChangedLogEntry(Hero oldLeader, Hero newLeader)
    {
      this.OldLeader = oldLeader;
      this.NewLeader = newLeader;
    }

    public override string ToString() => this.GetEncyclopediaText().ToString();

    public bool IsVisibleInEncyclopediaPageOf<T>(T obj) where T : MBObjectBase
    {
      return (object) obj == this.OldLeader || (object) obj == this.NewLeader || (object) obj == this.NewLeader.Clan;
    }

    public TextObject GetEncyclopediaText()
    {
      TextObject parent = new TextObject("{=o69PZuce}{OLD_LEADER.LINK} is no longer the head of the {CLAN_NAME}. {NEW_LEADER.LINK} has taken over as ruler of the clan.");
      parent.SetTextVariable("CLAN_NAME", this.NewLeader.Clan.EncyclopediaLinkWithName);
      StringHelpers.SetCharacterProperties("OLD_LEADER", this.OldLeader.CharacterObject, parent);
      StringHelpers.SetCharacterProperties("NEW_LEADER", this.NewLeader.CharacterObject, parent);
      return parent;
    }
  }
}
